<?php
/**
 * Copyright (c) 2006-2007, Julien PORTALIER
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright    Copyright (c) 2006-2007, Julien PORTALIER
 * @link         http://feather-cm.googlecode.com/
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

class TagcloudHelper extends Helper
{
	function render(&$tags, $base_link='', array $attr=array()/*, $levels=9, $css_class='tag_'*/)
	{
		if (empty($attr['rel'])) {
			$attr['rel'] = 'tag';
		}
		$levels    = 9;
		$css_class = 'tag_';
		
		$cloud = array();
		if (!empty($tags))
		{
			$min = min($tags);
			$max = max($tags);
			
			foreach($tags as $tag => $counter)
			{
				$curr_level = intval(($levels * ($counter - ($min - 1))) / (($max - ($min - 1)) + 1)) + 1;
				$swap_level = ($levels + 1) - $curr_level;
				
				$attr['title'] = sprintf(ngettext('One occurence', '%d occurences', $counter), $counter);
				$content = $this->link(str_replace(' ', '&nbsp;', $tag), $base_link.urlencode($tag), &$attr);
				array_push($cloud, $this->contentTag('li', $content, array('class' => $css_class.$swap_level)));
			}
		}
		return '<ul class="tagcloud">'.implode(' ', $cloud).'</ul>';
	}
}
?>